﻿using System;
using System.Collections.Generic;
using Super_Management_Mayhem.Content.Spritesheet;
using Super_Management_Mayhem.Screens.Playing.Points;
using Transformable_Engine_v2.Engine.Graphics;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace Super_Management_Mayhem.Screens.Playing.Maps
{
    public class CastleMap : BaseMap
    {
        private static readonly Dictionary<char, Enum> charToSprite = new Dictionary<char, Enum>
            {
                {'0', CastleEnvironmentSheet.BrickWall.TopLeft},
                {'1', CastleEnvironmentSheet.BrickWall.Top},
                {'2', CastleEnvironmentSheet.BrickWall.TopRight},
                {'3', CastleEnvironmentSheet.BrickWall.Left},
                {'4', CastleEnvironmentSheet.BrickWall.Center},
                {'5', CastleEnvironmentSheet.BrickWall.Right},
                {'6', CastleEnvironmentSheet.BrickWall.BottomLeft},
                {'7', CastleEnvironmentSheet.BrickWall.Bottom},
                {'8', CastleEnvironmentSheet.BrickWall.BottomRight},
                {'9', CastleEnvironmentSheet.BrickWall.TopLeftInward},
                {'A', CastleEnvironmentSheet.BrickWall.TopRightInward},
                {'B', CastleEnvironmentSheet.BrickWall.BottomLeftInward},
                {'C', CastleEnvironmentSheet.BrickWall.BottomRightInward},
                {'D', CastleEnvironmentSheet.StoneFloor.TopLeft},
                {'E', CastleEnvironmentSheet.StoneFloor.Top},
                {'F', CastleEnvironmentSheet.StoneFloor.TopRight},
                {'G', CastleEnvironmentSheet.StoneFloor.Left},
                {'H', CastleEnvironmentSheet.StoneFloor.Center},
                {'I', CastleEnvironmentSheet.StoneFloor.Right},
                {'J', CastleEnvironmentSheet.StoneFloor.BottomLeft},
                {'K', CastleEnvironmentSheet.StoneFloor.Bottom},
                {'L', CastleEnvironmentSheet.StoneFloor.BottomRight},
                {'M', CastleEnvironmentSheet.StoneFloor.TopLeftInward},
                {'N', CastleEnvironmentSheet.StoneFloor.TopRightInward},
                {'O', CastleEnvironmentSheet.StoneFloor.BottomLeftInward},
                {'P', CastleEnvironmentSheet.StoneFloor.BottomRightInward},
                {'Q', CastleEnvironmentSheet.StoneFloor.HallwayLeft},
                {'R', CastleEnvironmentSheet.StoneFloor.HallwayBottom},
                {'S', CastleEnvironmentSheet.StoneFloor.HallwayRight},
                {'T', CastleEnvironmentSheet.StoneFloor.HallwayTop},
                {'U', CastleEnvironmentSheet.StoneFloor.HallwayHorizontal},
                {'V', CastleEnvironmentSheet.StoneFloor.HallwayVertical},
                {'W', CastleEnvironmentSheet.StoneFloor.HallwayEndLeft},
                {'X', CastleEnvironmentSheet.StoneFloor.HallwayEndBottom},
                {'Y', CastleEnvironmentSheet.StoneFloor.HallwayEndRight},
                {'Z', CastleEnvironmentSheet.StoneFloor.HallwayEndTop},
                {'a', CastleEnvironmentSheet.StoneHole.TopLeft},
                {'b', CastleEnvironmentSheet.StoneHole.Top},
                {'c', CastleEnvironmentSheet.StoneHole.TopRight},
                {'d', CastleEnvironmentSheet.StoneHole.Left},
                {'e', CastleEnvironmentSheet.StoneHole.Right},
                {'f', CastleEnvironmentSheet.StoneHole.BottomLeft},
                {'g', CastleEnvironmentSheet.StoneHole.Bottom},
                {'h', CastleEnvironmentSheet.StoneHole.BottomRight},
            };

        public CastleMap() : base("Castle")
        {
        }

        protected override Sprite GetSpriteFromEnum(Enum wallType)
        {
            return CastleEnvironmentSheet.GetSprite(wallType);
        }

        public override int StartingPoints
        {
            get { return 100; }
        }

        protected override void LoadSpriteSheet()
        {
            CastleEnvironmentSheet.LoadContent();
        }

        protected override void AddTileLayerObjects()
        {
            AddWarp(2, 16, Color.Yellow, 48, 16);
            AddWarp(2, 17, Color.Yellow, 48, 17);
            AddWarp(49, 16, Color.Yellow, 3, 16);
            AddWarp(49, 17, Color.Yellow, 3, 17);

            AddWarp(19, 51, Color.Yellow, 18, 18);
            AddWarp(18, 51, Color.Yellow, 18, 18);

            AddWarp(32, 51, Color.Yellow, 33, 18);
            AddWarp(33, 51, Color.Yellow, 33, 18);
            
        }

        protected override void AddPointLayerObjects()
        {
            for (int i = 0; i < 10; i++)
            {
                AddPoint(26, 5, Point.PointType.Three);
            }
            for (int i = 0; i < 5; i++)
            {
                AddPoint(26, 5, Point.PointType.Five);
            }
            for (int i = 0; i < 5; i++)
            {
                AddPoint(26, 5, Point.PointType.Ten);
            }
        }

        protected override void AddCollisionLayerObjects()
        {
            Collisions.Add(new TE_Rectangle(-2, -2, 4, Size.Y + 4).ToGridBound());
            Collisions.Add(new TE_Rectangle(-2, -2, Size.X + 4, 4).ToGridBound());

            Collisions.Add(new TE_Rectangle(Size.X - 2, -2, 4, Size.Y + 4).ToGridBound());
            Collisions.Add(new TE_Rectangle(-2, Size.Y - 2, Size.X + 4, 4).ToGridBound());
        }

        protected override Enum GetSpriteFromChar(char c)
        {
            return charToSprite[c];
        }


        
    }
}